software master at the intersection of technology, science and art

home

download

iterators


Iterators expose an enumerable set one element at a time. To develop the GetEnumerator of the IEnumerator interface, an iterator is required. The keywords "yield return" returns an element at a time when iterating through a set. For example the foreach command is implemented for an array with the following GetEnumerator method

Array.GetEnumerator(){
for (i=0; i++; i < array.length){
yield return array[i]};
} }

The method returns an element with each call and a place holder for the next call in the for loop.